import repository from '@/repositories/user'
import jwtHelper from '@/common/js/jwtHelper'
import dateHelper from '@/common/js/dateHelper'

const getUser = () => {
  let userInfo = jwtHelper.getUserInfo()
  let user = {}
  user.requesterDomainId = userInfo.domainId
  user.requesterDisplayName = userInfo.displayName
  user.phone = userInfo.phone
  user.email = userInfo.mail
  return user
}

const addTempUserResult = async (userData) => {
  return await repository.addTempUser(userData)
}

const deleteTempUserResult = async (id) => {
  return await repository.deleteTempUser(id)
}

const getTempUserWithConditionResult = async (param) => {
  let data = await repository.getTempUserWithCondition(param)
  data.content.forEach(item => {
    item.createdAt = dateHelper.formatDate(item.createdAt)
    item.updatedAt = dateHelper.formatDate(item.updatedAt)
  })
  return data
}

const getTempUserDepartmentsResult = async () => {
  return await repository.getTempUserDepartments()
}

export default {
  getUser: getUser,
  getTempUserWithConditionResult: getTempUserWithConditionResult,
  getTempUserDepartmentsResult: getTempUserDepartmentsResult,
  addTempUserResult: addTempUserResult,
  deleteTempUserResult: deleteTempUserResult
}
